<template>
  <router-view />
</template>
<script>
import { myMACAddress,updateOnlineStatus } from "@/api/course.js";
import { ipc } from "@/utils/ipcRenderer";
import { ipcApiRoute, specialIpcRoute } from "@/utils/ipcMainApi";

import axios from "axios";
export default {
  name: "App",
  data() {
    return {
      statusInterval: null, // 用于存储定时器ID
    };
  },
  setup() {
    document.getElementById("loadingPage").remove();
  },
  created() {
    let set = JSON.parse(localStorage.getItem("set"));
    // 设置开机自启动 startup
    // 设置开机最小化 minimization

    // // 检查状态 - 没有Promise支持
    // const status = app.getLoginItemSettings();
    // console.log("是否自启动:", status.openAtLogin);
    this.getMac();
    if (set) {
      this.boot(set.startup);
      if (set.minimization == true) {
        ipc.invoke(ipcApiRoute.minimize).then((id) => {});
      }
    }
  },
  mounted() {
    this.updateOnlineStatus(); // 立即执行一次
  this.statusInterval = setInterval(() => {
    this.updateOnlineStatus();
  }, 5 * 60 * 1000); // 每 5 分钟执行一次
},
beforeUnmount() {
  if (this.statusInterval) {
    clearInterval(this.statusInterval);
    this.statusInterval = null;
  }
},
  methods: {
    boot(startup) {
      ipc.invoke(ipcApiRoute.boot, startup).then(() => {});
    },

    async getMac() {
      // //获取磨课
      // const res = await myMACAddress();
      // console.log(res, "reeeeeeee");

      // http://localhost:8080    http://192.168.1.117:8080
      try {
        const response = await axios.get(
          "http://192.168.1.117:8080/stream/myMACAddress"
        ); // 替换为你的API URL
        // this.users = response.data; // 假设返回的数据是一个用户列表数组
        console.error("response", response);
        // macAddress
        if (response.data) {
          // localStorage.setItem("macAddress", response.data);
          localStorage.setItem("macAddress", "00:1A:2B:3C:4D:5E");
        } else {
          localStorage.setItem("macAddress", "00:1A:2B:3C:4D:5E");
        }
      } catch (error) {
        console.error("There was an error!", error);
         localStorage.setItem("macAddress", "00:1A:2B:3C:4D:5E");
      }
    },
        async updateOnlineStatus() {
      const res = await  updateOnlineStatus({
      macAddress: localStorage.getItem("macAddress")
     })
      console.log(res, "更新状态");
    },
  },
};
</script>
<style scoped></style>
